$(function(){
    obj.init();
});

var obj = new JsFun();
function JsFun(){
    'use strict';
    return {
        dom: {
            btnView:null,
            frame: null,
            start: null,
            end: null
        },
        init: function () {

            this.dom.frame   = $('iframe');
            this.dom.start   = $('#startTime');
            this.dom.end     = $('#endTime');
            this.dom.btnView = $('#bt_view_usage');
            this.listener();
            this.funObj().viewUsage(false);
        },
        listener: function () {
            var $this = this;
            //点击查询
            $this.dom.btnView.click(function () {
                $this.funObj().viewUsage(true);
            });
            //加载完毕后关闭提示
            $this.dom.frame.load(function(){
                window.top.swal.close();
            });
        },
        funObj: function(){
            var $this = this;
            return {
                viewUsage: function (boolShowDialog) {
                    $this.dom.frame.attr('src', '');
                    setTimeout(function () {
                        var schoolId    = xhTool.getQuery('schoolId'),
                            startTime   = $this.dom.start.val(),
                            endTime     = $this.dom.end.val(),
                            userId      = xhTool.getQuery('userId');
                        if (!schoolId) {
                            window.top.xhTop.showError('学校为必选项！');
                            return false;
                        }
                        if (!startTime || !endTime) {
                            window.top.xhTop.showError('时间不能为空！');
                            return false;
                        }
                        $this.dom.frame.attr('src',
                            baseUrl + 'tch/tchAppFix?'
                            + xhTool.parseParam({schoolId: schoolId, startTime: startTime, endTime: endTime,userId:userId})
                        );
                        if(boolShowDialog){
                            window.top.swal({
                                title: '统计执行中！请耐心等待...',
                                showConfirmButton: false,
                                type: 'success',
                                allowOutsideClick: false
                            });
                            setTimeout(function () {
                                window.top.swal.close();
                            }, 30 * 1000);
                        }
                    }, 0);
                }
            }
        }
    }
}